  
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spShippingStatusReportNonPaymentLess7Report]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [spShippingStatusReportNonPaymentLess7Report]
GO


CREATE PROCEDURE spShippingStatusReportNonPaymentLess7Report	
@OfficeID int,
@Type int
AS
SELECT [ShippingStatusReport].[ID],
	[REQ],
	[OrderDate],
	[ContainerSize],
	[LP],
	[PONo_Office],
	[PONo_Type],
	[PONo_Supplier],
	[PONo_Number],
	[IsPrimary],
	[PONo_Consolidation],
	[AccNo],
	[CustomerOrLocation],
	[FinalDestination],
	[Description],
	[FactoryETD],
	[ShippingDate],
	[ShippingLine],
	[Vessel],
	[ContainerNo],
	[ETA],
	[Week],
	[ArrivalPort],
	[PI],
	[Payment],
	[DocReceived],
	[CompletedDate],
	[BulkType],
	[ModifiedDate],
	[BulkOrderNo],
	[PayAuth],
	[ContainerDeliveried],
	[POInOpera],
	[InvValue],
	[PayDate],
	[Remarks],
	[SInvoiced],
	[SuppOrderNo],
	[OfficeID],
	[CustPONo],
	[OnHold],
	[BulkOrderOfficeID],
	[SInvoicedPd],
	[Catalogue],
	[ShippingLineID],
	[CatalogID],
	SalesInvoiceValue,
	SalesInvoiceDate,
	SalesPaymentDue,
	SalesOrder
FROM
	[ShippingStatusReport] 
WHERE 
((@Type = 0 AND CompletedDate IS NULL) OR @Type=1)
AND (OfficeID = @OfficeID)
AND ([PONo_Type] = 'D' OR [PONo_Type] = 'H')
AND (SalesInvoiceDate IS NULL)
AND ((SalesPaymentDue IS NOT NULL) AND (DATEDIFF(day, getdate(), SalesPaymentDue) <= 7) AND (DATEDIFF(day, getdate(), SalesPaymentDue) >= 0) )
ORDER BY SalesPaymentDue, [CustomerOrLocation], [CustPONo], [REQ], [IsPrimary] asc


GO

	
  